/*
>> PixelToPixelOp.s
>>
>> Pixel operation skeleton for Xetal, allowing buffer and scalar inputs, and
>> buffer outputs. Adapted from PixelToPixelOp.py.
>>
>> Necessary transformations:
>> * All types to reg
>> * Locals -> lmem
>>
>> Author: Wouter Caarls
>> Date:   06-04-2005
*/

#include "stdsc.h"
#include "stdstratego.h"
#include "xtcstrategies.h"
	
typedef int reg;
typedef void lmem;

void PixelToPixelOp(argcode_t *argcode, int arguments, code body)
{
reg _ii, _stride, _first = 0;
code locals[];

lmem larg0, larg1, larg2, larg3, larg4;
reg  rarg0, rarg1, rarg2, rarg3, rarg4;

/* Build a list of locals, and replace argument occurances */
for (_ii=0; _ii < arguments; _ii++)
{
  if (argcode[_ii].argtype == ARG_STREAM_IN ||
      argcode[_ii].argtype == ARG_STREAM_OUT)
  {
    /* Replace occurances */
    body = replace(deref(argcode[_ii].id), makeid(`larg`, _ii), body); 
    locals[@len(locals)] = makeid(`larg`, _ii);
  }
  else
  {
    /* *** ONLY WORKS FOR IMMEDIATES *** */
    @declare(addpointer(argcode[_ii].datatype), argcode[_ii].id);
    if (@dataclass(argcode[_ii].datatype) == DATACLASS_INTEGER)
      @argcode[_ii].id = &(@argcode[_ii].argid).data.d;
    else if (@dataclass(argcode[_ii].datatype) == DATACLASS_FLOAT)
      @argcode[_ii].id = &(@argcode[_ii].argid).data.f;
  }
  argcode[_ii].state.buffer = 1;
  argcode[_ii].state.state = 0;
  argcode[_ii].state.delay = 0;
}

/* Propagate locals */
locals = @getlocals(locals, body);

/* If-conversion */
body = ifconversion(locals, body); 

/* Propagate locals */
locals = @getlocals(locals, body);

/* Replace all types by the "reg" type, and
 * Make all locals lmems instead of regs */
body = makelmem(locals, makereg(body));

/* Run the instantiation function */
linebyline(argcode, arguments)
{
}
{
  @body;
}
{
};
}
